package com.Home
{
	import com.*;
	import com.Engine.*;
	import com.Packet.*;
	import com.UI.*;
	
	import flash.display.*;
	import flash.events.*;
	import flash.external.*;
	import flash.filters.*;
	import flash.geom.*;
	import flash.system.*;
	import flash.text.*;
	import flash.ui.*;
	import flash.utils.*;
	
	import org.aswing.*;
	import org.aswing.border.*;
	import org.aswing.border.EmptyBorder;
	import org.aswing.colorchooser.*;
	import org.aswing.dnd.*;
	import org.aswing.event.*;
	import org.aswing.ext.*;
	import org.aswing.geom.*;
	import org.aswing.tree.AbstractLayoutCache;
	public class FrameHomeBuilding4Market extends FrameHomeBuilding
	{
		private var btn_buy:JButton;
		private var btn_sell:JButton;
		public function FrameHomeBuilding4Market()
		{
			btn_buy = new JButton();
			btn_buy.setSize(new IntDimension(72, 23));
			btn_buy.setPreferredSize(new IntDimension(72, 23));
			btn_buy.setText("购买资源");
			
			btn_sell = new JButton();
			btn_sell.setSize(new IntDimension(72, 23));
			btn_sell.setPreferredSize(new IntDimension(72, 23));
			btn_sell.setText("出售资源");
			
			panelButtons.append(btn_buy);
			panelButtons.append(btn_sell);
			
			btn_buy.wrapSimpleButton(Client.getUIElement("btn_4") as SimpleButton);
			btn_sell.wrapSimpleButton(Client.getUIElement("btn_4") as SimpleButton);
			
			var filter:GlowFilter;
			var font:ASFont = new ASFont("宋体", 14, false, false, false, false);
			filter = new GlowFilter(0x000000, 1, 2, 2, 5);
			btn_buy.setFont(font);
			btn_buy.setForeground(ASColor.WHITE);
			btn_buy.setTextFilters(new Array(filter));
			
			btn_sell.setFont(font);
			btn_sell.setForeground(ASColor.WHITE);
			btn_sell.setTextFilters(new Array(filter));
			
			btn_sell.addActionListener(function():void{FrameHomeMarketSell.show();});
			btn_buy.addActionListener(function():void{FrameHomeMarketBuy.show();});

		}

		override public function setImages():void
		{
			super.setImages();
			var img_char_background:DisplayObject = Client.getUIElement("img_home_bg_4") as DisplayObject
			setBackgroundDecorator(new AssetBackground(img_char_background));
			setSize(new IntDimension(img_char_background.width, img_char_background.height));
			setPreferredSize(new IntDimension(img_char_background.width, img_char_background.height));
			setSizeWH(img_char_background.width,img_char_background.height);
			setLocationXY((Engine.W - img_char_background.width) / 2,(Engine.H - img_char_background.height)/2);
			btn_dispatch.addActionListener(function():void{FrameHomeDispatch.show(objDest,_frame);});
			btn_accelerate.addActionListener(function():void{FrameHomeAccelerate.show(_frame);});
		}
		public static var _frame:FrameHomeBuilding4Market = null;
		public static function show(obj:ObjectHomeBuilding):void
		{
			if(_frame == null)
			{
				_frame = new FrameHomeBuilding4Market();
				PanelMainHelp.getInstance().addChild(_frame);
			}
			if(!isShowing())
			{
				_frame.show();
				_frame.setLocationXY((Engine.W - _frame.width) / 2,(Engine.H - _frame.height)/2);
				PanelMainHelp.getInstance().bringToTop(_frame);
			}
			_frame.update(obj);
			
		}
		public static function hide():void
		{
			if(isShowing())_frame.hide();
		}
		public static function isShowing():Boolean
		{
			return(_frame != null&& _frame.isShowing());
		}
		public static function update():void
		{
			if(FrameHomeMarketSell.isShowing())
				FrameHomeMarketSell._frame.update();
			if(FrameHomeMarketBuy.isShowing())
				FrameHomeMarketBuy._frame.update();
		}
	}
}

import com.*;
import com.Engine.*;
import com.Home.*;
import com.Home.FrameHomeBuilding;
import com.Packet.*;
import com.UI.*;

import flash.display.*;
import flash.events.*;
import flash.external.*;
import flash.filters.*;
import flash.geom.*;
import flash.system.*;
import flash.text.*;
import flash.ui.*;
import flash.utils.*;

import gs.*;
import gs.easing.*;
import gs.events.TweenEvent;

import org.aswing.*;
import org.aswing.border.*;
import org.aswing.border.EmptyBorder;
import org.aswing.colorchooser.*;
import org.aswing.dnd.*;
import org.aswing.event.*;
import org.aswing.ext.*;
import org.aswing.geom.*;
import org.aswing.tree.AbstractLayoutCache;

/**
 * MyPaneHomeMarketSell
 */
class FrameHomeMarketSell  extends JFrame
{
	
	//members define
	private var labelFoodPrice:JLabel;
	private var labelWoodPrice:JLabel;
	private var txtFood:JTextField;
	private var txtWood:JTextField;
	private var labelInventoryFood:JLabel;
	private var labelInventoryWood:JLabel;
	private var labelMoney:JLabel;
	private var panel46:JPanel;
	private var btn_sell:JButton;
	
	private var btn_close:JButton;
	public function FrameHomeMarketSell()
	{
		setResizable(false);
		setBorder(new EmptyBorder());
		
		btn_close = new JButton();
		btn_close.setLocation(new IntPoint(198, 0));
		btn_close.setSize(new IntDimension(27, 27));
		btn_close.setPreferredSize(new IntDimension(27, 27));
		this.getTitleBar().setCloseButton(btn_close);
		this.setClipMasked(false);
		getContentPane().setClipMasked(false);
		getTitleBar().getFrame().setClipMasked(false);
		btn_close.setClipMasked(false);
		getTitleBar().setMinimizeHeight(32);
		
		//component creation
		setSize(new IntDimension(366, 193));
		setPreferredSize(new IntDimension(366, 193));
		var layout0:EmptyLayout = new EmptyLayout();
		getContentPane().setLayout(layout0);
		
		labelFoodPrice = new JLabel();
		labelFoodPrice.setLocation(new IntPoint(9, 6));
		labelFoodPrice.setSize(new IntDimension(349, 20));
		labelFoodPrice.setPreferredSize(new IntDimension(349, 20));
		labelFoodPrice.setText("价格:10铜币/100仙粮");
		
		labelWoodPrice = new JLabel();
		labelWoodPrice.setLocation(new IntPoint(9, 26));
		labelWoodPrice.setSize(new IntDimension(349, 20));
		labelWoodPrice.setPreferredSize(new IntDimension(349, 20));
		labelWoodPrice.setText("价格:10铜币/100仙木");
		
		txtFood = new JTextField();
		txtFood.setLocation(new IntPoint(123, 50));
		txtFood.setSize(new IntDimension(97, 20));
		txtFood.setPreferredSize(new IntDimension(97, 20));
		
		txtWood = new JTextField();
		txtWood.setLocation(new IntPoint(123, 73));
		txtWood.setSize(new IntDimension(97, 20));
		txtWood.setPreferredSize(new IntDimension(97, 20));
		
		labelInventoryFood = new JLabel();
		labelInventoryFood.setLocation(new IntPoint(272, 52));
		labelInventoryFood.setSize(new IntDimension(86, 16));
		labelInventoryFood.setPreferredSize(new IntDimension(86, 16));
		labelInventoryFood.setText("label");
		
		labelInventoryWood = new JLabel();
		labelInventoryWood.setLocation(new IntPoint(272, 75));
		labelInventoryWood.setSize(new IntDimension(86, 16));
		labelInventoryWood.setPreferredSize(new IntDimension(86, 16));
		labelInventoryWood.setText("label");
		
		labelMoney = new JLabel();
		labelMoney.setLocation(new IntPoint(118, 98));
		labelMoney.setSize(new IntDimension(108, 16));
		labelMoney.setPreferredSize(new IntDimension(108, 16));
		labelMoney.setText("label");
		
		panel46 = new JPanel();
		panel46.setLocation(new IntPoint(0, 120));
		panel46.setSize(new IntDimension(366, 25));
		panel46.setPreferredSize(new IntDimension(366, 25));
		var layout1:CenterLayout = new CenterLayout();
		panel46.setLayout(layout1);
		
		btn_sell = new JButton();
		btn_sell.setLocation(new IntPoint(158, 0));
		btn_sell.setSize(new IntDimension(49, 25));
		btn_sell.setPreferredSize(new IntDimension(49, 25));
		btn_sell.setText("label");
		
		//component layoution
		getContentPane().append(labelFoodPrice);
		getContentPane().append(labelWoodPrice);
		getContentPane().append(txtFood);
		getContentPane().append(txtWood);
		getContentPane().append(labelInventoryFood);
		getContentPane().append(labelInventoryWood);
		getContentPane().append(labelMoney);
		getContentPane().append(panel46);
		
		panel46.append(btn_sell);
		
		setImages();
	}
	public function setImages():void
	{
		
		var img_char_background:DisplayObject = Client.getUIElement("img_home_resource_sell_bg") as DisplayObject
		setBackgroundDecorator(new AssetBackground(img_char_background));
		setSize(new IntDimension(img_char_background.width, img_char_background.height));
		setPreferredSize(new IntDimension(img_char_background.width, img_char_background.height));
		setSizeWH(img_char_background.width,img_char_background.height);
		setLocationXY((Engine.W - img_char_background.width) / 2,(Engine.H - img_char_background.height)/2);
		
		btn_sell.wrapSimpleButton(Client.getUIElement("btn_home_resource_sell") as SimpleButton);
		btn_sell.setText("");


		btn_close.wrapSimpleButton(Client.getUIElement("btn_close") as SimpleButton);
		
		
		var filter:GlowFilter;
		var font:ASFont = new ASFont("宋体", 14, false, false, false, false);
		filter = new GlowFilter(0x000000, 1, 2, 2, 5);
		btn_sell.setFont(font);
		btn_sell.setForeground(ASColor.WHITE);
		btn_sell.setTextFilters(new Array(filter));
		
		btn_sell.addActionListener(onBtnSell);
		getContentPane().setClipMasked(false);
		setClipMasked(false);
		
		font = new ASFont("宋体", 12, false, false, false, false);
		labelFoodPrice.setForeground(ASColor.WHITE);
		labelFoodPrice.setFont(font);
		labelFoodPrice.setTextFilters(new Array(filter));
		
		labelWoodPrice.setForeground(ASColor.WHITE);
		labelWoodPrice.setFont(font);
		labelWoodPrice.setTextFilters(new Array(filter));
		
		labelInventoryFood.setForeground(ASColor.WHITE);
		labelInventoryFood.setFont(font);
		labelInventoryFood.setTextFilters(new Array(filter));
		
		labelInventoryWood.setForeground(ASColor.WHITE);
		labelInventoryWood.setFont(font);
		labelInventoryWood.setTextFilters(new Array(filter));
		
		labelMoney.setForeground(ASColor.WHITE);
		labelMoney.setFont(font);
		labelMoney.setTextFilters(new Array(filter));
		
		txtWood.setBackgroundDecorator(null);
		txtFood.setBackgroundDecorator(null);
		
		txtWood.setFont(font);
		txtWood.setForeground(ASColor.WHITE);
		txtFood.setFont(font);
		txtFood.setForeground(ASColor.WHITE);
		txtWood.setText("100");
		txtFood.setText("100");
		txtWood.addEventListener(FocusKeyEvent.FOCUS_KEY_UP,onTextInput);
		txtFood.addEventListener(FocusKeyEvent.FOCUS_KEY_UP,onTextInput);
		
		txtWood.setRestrict('0-9');
		txtFood.setRestrict('0-9');
		
		labelInventoryWood.setText(CharInfo.wood.toString());
		labelInventoryFood.setText(CharInfo.food.toString());
		
		addEventListener(AWEvent.SHOWN,FrameHomeBuilding.onSecondFrameShown);
		addEventListener(FrameEvent.FRAME_CLOSING,FrameHomeBuilding.onSecondFrameClosing);
		addEventListener(AWEvent.HIDDEN,FrameHomeBuilding.onSecondFrameClosing);
	}
	private function onTextInput(e:Event):void
	{
		labelMoney.setText(((int(txtWood.getText())+int(txtFood.getText()))/10).toString()+'/'+CharInfo.money);
	}
	private function onBtnSell(e:Event):void
	{
		Client.getInstance().sendPacketLogic(1312,[int(txtWood.getText()),int(txtFood.getText())]);
	}
	public function update():void
	{
		onTextInput(null);
		labelInventoryWood.setText(CharInfo.wood.toString());
		labelInventoryFood.setText(CharInfo.food.toString());
	}
	public static var _frame:FrameHomeMarketSell = null;
	public static function show():void
	{
		if(_frame == null)
		{
			_frame = new FrameHomeMarketSell();
			PanelMainHelp.getInstance().addChild(_frame);
		}
		if(!isShowing())
		{
			_frame.show();
			_frame.setLocationXY((Engine.W - _frame.width) / 2,(Engine.H - _frame.height)/2);
			PanelMainHelp.getInstance().bringToTop(_frame);
		}
		_frame.update();
		var frameHomeBuilding:FrameHomeBuilding = FrameHomeBuilding4Market._frame;
		var teamDestX:int = (Engine.W - (_frame.width+frameHomeBuilding.width))/2;
		var teamDestY:int = (Engine.H - frameHomeBuilding.height)/2;
		
		var listDestX:int = teamDestX + frameHomeBuilding.width;
		var listDestY:int = teamDestY + (frameHomeBuilding.height - _frame.height)/2;
		
		var tween:TweenLite = TweenLite.to(frameHomeBuilding, 0.3, {x:teamDestX, y:teamDestY});
		var list_tween:TweenLite = TweenLite.to(_frame, 0.3, {x:listDestX, y:listDestY});
		
	}
	public static function hide():void
	{
		if(isShowing())_frame.hide();
	}
	public static function isShowing():Boolean
	{
		return(_frame != null&& _frame.isShowing());
	}
	
	
}

/**
 * MyPaneHomeMarketBuy
 */
class FrameHomeMarketBuy extends JFrame
{
	
	//members define
	private var labelFoodPrice:JLabel;
	private var labelWoodPrice:JLabel;
	private var txtFood:JTextField;
	private var txtWood:JTextField;
	private var labelInventoryFood:JLabel;
	private var labelInventoryWood:JLabel;
	private var labelMoney:JLabel;
	private var panel46:JPanel;
	private var btn_buy:JButton;
	
	private var btn_close:JButton;
	public function FrameHomeMarketBuy()
	{
		setResizable(false);
		setBorder(new EmptyBorder());
		
		btn_close = new JButton();
		btn_close.setLocation(new IntPoint(198, 0));
		btn_close.setSize(new IntDimension(27, 27));
		btn_close.setPreferredSize(new IntDimension(27, 27));
		this.getTitleBar().setCloseButton(btn_close);
		this.setClipMasked(false);
		getContentPane().setClipMasked(false);
		getTitleBar().getFrame().setClipMasked(false);
		btn_close.setClipMasked(false);
		getTitleBar().setMinimizeHeight(32);
		
		//component creation
		setSize(new IntDimension(366, 193));
		setPreferredSize(new IntDimension(366, 193));
		var layout0:EmptyLayout = new EmptyLayout();
		getContentPane().setLayout(layout0);
		
		labelFoodPrice = new JLabel();
		labelFoodPrice.setLocation(new IntPoint(9, 6));
		labelFoodPrice.setSize(new IntDimension(349, 20));
		labelFoodPrice.setPreferredSize(new IntDimension(349, 20));
		labelFoodPrice.setText("价格:100铜币/100仙粮");
		
		labelWoodPrice = new JLabel();
		labelWoodPrice.setLocation(new IntPoint(9, 26));
		labelWoodPrice.setSize(new IntDimension(349, 20));
		labelWoodPrice.setPreferredSize(new IntDimension(349, 20));
		labelWoodPrice.setText("价格:100铜币/100仙木");
		
		txtFood = new JTextField();
		txtFood.setLocation(new IntPoint(123, 50));
		txtFood.setSize(new IntDimension(97, 20));
		txtFood.setPreferredSize(new IntDimension(97, 20));
		
		txtWood = new JTextField();
		txtWood.setLocation(new IntPoint(123, 73));
		txtWood.setSize(new IntDimension(97, 20));
		txtWood.setPreferredSize(new IntDimension(97, 20));
		
		labelInventoryFood = new JLabel();
		labelInventoryFood.setLocation(new IntPoint(272, 52));
		labelInventoryFood.setSize(new IntDimension(86, 16));
		labelInventoryFood.setPreferredSize(new IntDimension(86, 16));
		labelInventoryFood.setText("label");
		
		labelInventoryWood = new JLabel();
		labelInventoryWood.setLocation(new IntPoint(272, 75));
		labelInventoryWood.setSize(new IntDimension(86, 16));
		labelInventoryWood.setPreferredSize(new IntDimension(86, 16));
		labelInventoryWood.setText("label");
		
		labelMoney = new JLabel();
		labelMoney.setLocation(new IntPoint(118, 98));
		labelMoney.setSize(new IntDimension(108, 16));
		labelMoney.setPreferredSize(new IntDimension(108, 16));
		labelMoney.setText("label");
		
		panel46 = new JPanel();
		panel46.setLocation(new IntPoint(0, 123));
		panel46.setSize(new IntDimension(366, 25));
		panel46.setPreferredSize(new IntDimension(366, 25));
		var layout1:CenterLayout = new CenterLayout();
		panel46.setLayout(layout1);
		
		btn_buy = new JButton();
		btn_buy.setLocation(new IntPoint(158, 0));
		btn_buy.setSize(new IntDimension(49, 25));
		btn_buy.setPreferredSize(new IntDimension(49, 25));
		btn_buy.setText("label");
		
		//component layoution
		getContentPane().append(labelFoodPrice);
		getContentPane().append(labelWoodPrice);
		getContentPane().append(txtFood);
		getContentPane().append(txtWood);
		getContentPane().append(labelInventoryFood);
		getContentPane().append(labelInventoryWood);
		getContentPane().append(labelMoney);
		getContentPane().append(panel46);
		
		panel46.append(btn_buy);
		
		setImages();
	}
	public function setImages():void
	{
		
		var img_char_background:DisplayObject = Client.getUIElement("img_home_resource_buy_bg") as DisplayObject
		setBackgroundDecorator(new AssetBackground(img_char_background));
		setSize(new IntDimension(img_char_background.width, img_char_background.height));
		setPreferredSize(new IntDimension(img_char_background.width, img_char_background.height));
		setSizeWH(img_char_background.width,img_char_background.height);
		setLocationXY((Engine.W - img_char_background.width) / 2,(Engine.H - img_char_background.height)/2);
		
		btn_buy.wrapSimpleButton(Client.getUIElement("btn_home_resource_buy") as SimpleButton);
		btn_buy.setText("");
		
		
		btn_close.wrapSimpleButton(Client.getUIElement("btn_close") as SimpleButton);
		
		
		var filter:GlowFilter;
		var font:ASFont = new ASFont("宋体", 14, false, false, false, false);
		filter = new GlowFilter(0x000000, 1, 2, 2, 5);
		btn_buy.setFont(font);
		btn_buy.setForeground(ASColor.WHITE);
		btn_buy.setTextFilters(new Array(filter));
		
		btn_buy.addActionListener(onBtnBuy);
		getContentPane().setClipMasked(false);
		setClipMasked(false);
		
		font = new ASFont("宋体", 12, false, false, false, false);
		labelFoodPrice.setForeground(ASColor.WHITE);
		labelFoodPrice.setFont(font);
		labelFoodPrice.setTextFilters(new Array(filter));
		
		labelWoodPrice.setForeground(ASColor.WHITE);
		labelWoodPrice.setFont(font);
		labelWoodPrice.setTextFilters(new Array(filter));
		
		labelInventoryFood.setForeground(ASColor.WHITE);
		labelInventoryFood.setFont(font);
		labelInventoryFood.setTextFilters(new Array(filter));
		
		labelInventoryWood.setForeground(ASColor.WHITE);
		labelInventoryWood.setFont(font);
		labelInventoryWood.setTextFilters(new Array(filter));
		
		labelMoney.setForeground(ASColor.WHITE);
		labelMoney.setFont(font);
		labelMoney.setTextFilters(new Array(filter));
		
		txtWood.setBackgroundDecorator(null);
		txtFood.setBackgroundDecorator(null);
		txtWood.setFont(font);
		txtWood.setForeground(ASColor.WHITE);
		txtFood.setFont(font);
		txtFood.setForeground(ASColor.WHITE);
		txtWood.setText("100");
		txtFood.setText("100");
		txtWood.addEventListener(FocusKeyEvent.FOCUS_KEY_UP,onTextInput);
		txtFood.addEventListener(FocusKeyEvent.FOCUS_KEY_UP,onTextInput);
		
		txtWood.setRestrict('0-9');
		txtFood.setRestrict('0-9');
		
		labelInventoryWood.setText(CharInfo.wood.toString());
		labelInventoryFood.setText(CharInfo.food.toString());
		
		addEventListener(AWEvent.SHOWN,FrameHomeBuilding.onSecondFrameShown);
		addEventListener(FrameEvent.FRAME_CLOSING,FrameHomeBuilding.onSecondFrameClosing);
		addEventListener(AWEvent.HIDDEN,FrameHomeBuilding.onSecondFrameClosing);
	}
	private function onTextInput(e:Event):void
	{
		labelMoney.setText((int(txtWood.getText())+int(txtFood.getText())).toString()+'/'+CharInfo.money);
	}
	private function onBtnBuy(e:Event):void
	{
		Client.getInstance().sendPacketLogic(1311,[int(txtWood.getText()),int(txtFood.getText())]);
	}
	public function update():void
	{
		onTextInput(null);
		labelInventoryWood.setText(CharInfo.wood.toString());
		labelInventoryFood.setText(CharInfo.food.toString());
	}
	public static var _frame:FrameHomeMarketBuy = null;
	public static function show():void
	{
		if(_frame == null)
		{
			_frame = new FrameHomeMarketBuy();
			PanelMainHelp.getInstance().addChild(_frame);
		}
		if(!isShowing())
		{
			_frame.show();
			_frame.setLocationXY((Engine.W - _frame.width) / 2,(Engine.H - _frame.height)/2);
			PanelMainHelp.getInstance().bringToTop(_frame);
		}
		_frame.update();
		var frameHomeBuilding:FrameHomeBuilding = FrameHomeBuilding4Market._frame;
		var teamDestX:int = (Engine.W - (_frame.width+frameHomeBuilding.width))/2;
		var teamDestY:int = (Engine.H - frameHomeBuilding.height)/2;
		
		var listDestX:int = teamDestX + frameHomeBuilding.width;
		var listDestY:int = teamDestY + (frameHomeBuilding.height - _frame.height)/2;
		
		var tween:TweenLite = TweenLite.to(frameHomeBuilding, 0.3, {x:teamDestX, y:teamDestY});
		var list_tween:TweenLite = TweenLite.to(_frame, 0.3, {x:listDestX, y:listDestY});
		
	}
	public static function hide():void
	{
		if(isShowing())_frame.hide();
	}
	public static function isShowing():Boolean
	{
		return(_frame != null&& _frame.isShowing());
	}
}